package com.controller;

import com.entity.BType;
import com.service.impl.BGoodsServiceImpl;
import com.service.impl.BTypeServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.*;

@Controller
public class IndexController {
    @Resource
    BGoodsServiceImpl bGoodsService;
    @Resource
    BTypeServiceImpl bTypeService;
    @GetMapping(value = "goodDetail")
    public String goodDetail(int id, Model model) {
        try {
            return "client/detail";
        } catch (Exception e) {
            e.printStackTrace();
            return "client/login";
        }
    }
    @GetMapping(value = "list")
    public String goodList(Model model) {
        try {
            List<BType> typeList = bTypeService.list();
  //          Map<String, List<BGoods>> goodList = new LinkedHashMap<>();
    //        QueryWrapper wrapper = QueryWrapper.create().limit(6);
      //      List<BType> typeList = bTypeService.getMapper().selectListByQuery(wrapper);
       //     for (BType bType : typeList) {
         //       int typeId = bType.getId();
           //     String typeName = bType.getTypeName();
   //             wrapper = QueryWrapper.create().where(BGoodsTableDef.B_GOODS.GOOD_NAME.eq(typeId)).limit(4);
     //           List<BGoods> goods = bGoodsService.list(wrapper);
       //         goodList.put(typeName, goods);
         //   }
            model.addAttribute("goodType", typeList);
            return "client/list";
        //    model.addAttribute("goodList", goodList);
        } catch (Exception e) {
            e.printStackTrace();
            return "client/login";
        }


    }}

